package jp.sourceforge.talisman.mds.distance;

/*
 * $Id: AbstractClusterDistanceCalculator.java,v 1.1 2009/09/12 05:06:09 weiwei Exp $
 */

import jp.sourceforge.talisman.mds.cluster.Cluster;

/**
 * 
 * @author Haruaki Tamada
 * @version $Revision: 1.1 $ 
 */
public abstract class AbstractClusterDistanceCalculator implements ClusterDistanceCalculator{
    private ItemDistanceCalculator calculator;

    public AbstractClusterDistanceCalculator(ItemDistanceAlgorithm algorithm){
        setItemDistanceCalculator(algorithm);
    }

    public AbstractClusterDistanceCalculator(){
    }

    public final ItemDistanceCalculator getItemDistanceCalculator(){
        return calculator;
    }

    public final void setItemDistanceCalculator(ItemDistanceAlgorithm algorithm){
        if(algorithm == null){
            throw new NullPointerException();
        }
        setItemDistanceCalculator(getCalculator(algorithm));
    }

    public void setItemDistanceCalculator(ItemDistanceCalculator idc){
        if(idc == null){
            throw new NullPointerException();
        }
        this.calculator = idc;
    }

    public static final ItemDistanceCalculator getCalculator(ItemDistanceAlgorithm algorithm){
        DistanceCalculatorFactory factory = DistanceCalculatorFactory.getInstance();
        return factory.getItemDistanceCalculator(algorithm);
    }

    public abstract double update(Cluster ci, Cluster cj, Cluster ck, double dij, double dik, double djk);

    public abstract double calculate(Cluster c1, Cluster c2);

    public abstract ClusterDistanceAlgorithm getAlgorithm();
}
